$( document ).ready(function() {
	if($(".userlogin-form").length > 0) {
		$(".userlogin-form").validate({
			submitHandler: function(form) {
				var password = $.md5($( "#loginPassword" ).val());
				$( "#loginPassword" ).val(password);
				form.submit();
			}
		});
	}

	if($(".userlogin-edit-form").length > 0) {
		$(".userlogin-edit-form").validate({
			rules: {
				"guiUserLogin.username" : {
					required: true
				},
				"guiUserLogin.password": {
					required: true
				},
				"guiUserLogin.confirmPassword": {
					required: true
				}
			},
			messages: {
				"guiUserLogin.username" : {
					required: "Please enter a login username"
				},
				"guiUserLogin.password": {
					required: "Please enter login password"
				},
				"guiUserLogin.confirmPassword": {
					required: "Please confirm login password"
				}
			},
			submitHandler: function(form) {
				var password = $.md5($( "#oldLoginPassword" ).val());
				$( "#oldLoginPassword" ).val(password);

				var password = $.md5($( "#loginPassword" ).val());
				$( "#loginPassword" ).val(password);

				var password = $.md5($( "#confirmLoginPassword" ).val());
				$( "#confirmLoginPassword" ).val(password);
				form.submit();
			}
		});
	}
	
	//error message notifier
	if ($("ul.errorMessage li span").length > 0) {
		$("ul.errorMessage li span").each(function(){
			$.Notify({
					 	  caption: "Try it!",
						  content: $(this).text(),
						  timeout: 5000,
						  style: {background: '#1ba1e2', color: 'white'}
					 });
		});
	}
			
});
